package com.csc.yunting.oss.controller;

import com.atguigu.srb.base.result.ResponseVo;
import com.csc.yunting.oss.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/oss/")
public class OssController {
    @Resource
    OssService ossService;
    @ApiOperation("文件上传")
    @PostMapping("upload")
    //参数2： 上传的文件保存到 oss桶中的哪个目录下
    public ResponseVo upload(MultipartFile file,
                             @RequestParam("module") String module){
        String path = ossService.upload(file,module);
        return ResponseVo.ok().data("path",path);
    }
    //https://sh221109-srb.oss-cn-shanghai.aliyuncs.com/img/2023/03/31/1680230410991_f295ba.jpg
    @ApiOperation("删除文件")
    @DeleteMapping("delete")
    public ResponseVo delete(@RequestParam(value = "path",required = true) String path){
        ossService.deleteFile(path);
        return ResponseVo.ok().message("删除成功");
    }
}
